<template>
  <view class="erplist">
    <view class="erpitem" @click="classification()" style="background: #3aaeff">
      <view class="erpitem_img">
        <image src="../../static/image/category1.png" mode=""></image>
      </view>
      <text>分类管理</text>
    </view>
    <view class="erpitem" @click="orderlistClick()" style="background: #fbc769">
      <view class="erpitem_img">
        <image src="../../static/image/icon-.png" mode=""></image>
      </view>
      <text>订单管理</text>
    </view>
    <!-- <view class="erpitem" @click="adminClick()" style="background: #ff7676">
      <view class="erpitem_img">
        <image src="../../static/image/huiyuan.png" mode=""></image>
      </view>
      <text>会员管理</text>
    </view> -->
    <!-- 会员卡管理 -->
    <view class="erpitem" @click="vipCardClick()" style="background: #ff7676">
      <view class="erpitem_img">
        <image src="../../static/image/huiyuan.png" mode=""></image>
      </view>
      <text>会员卡管理</text>
    </view>
    <!-- <view class="erpitem">
			<view class="erpitem_img">
				<image src="../../static/image/huodong-copy.png" mode=""></image>
			</view>
			<text>活动管理</text>
		</view> -->
    <view class="erpitem" @click="financeClick()" style="background: #d37cff">
      <view class="erpitem_img">
        <image src="../../static/image/caiwu.png" mode=""></image>
      </view>
      <text>财务管理</text>
    </view>
    <!-- <view class="erpitem" @click="stockClick()" style="background: #85a5ff;">
			<view class="erpitem_img">
				<image src="../../static/image/kucun.png" mode=""></image>
			</view>
			<text>库存盘点</text>
		</view> -->
    <view
      class="erpitem"
      style="background: #3ad2ff"
      @click="goodsadminClick()"
    >
      <view class="erpitem_img">
        <image src="../../static/image/kucun.png" mode=""></image>
      </view>
      <text>商品管理</text>
    </view>
    <view class="erpitem" style="background: #ff7c4a" @click="returnClick()">
      <view class="erpitem_img">
        <image src="../../static/image/kucun.png" mode=""></image>
      </view>
      <text>归还商品</text>
    </view>
    <view class="erpitem" style="background: #9d86fb" @click="cashierClick()">
      <view class="erpitem_img">
        <image src="../../static/image/kucun.png" mode=""></image>
      </view>
      <text>收银台</text>
    </view>
    <!-- 空白 -->
    <!-- 商品清洗 -->
    <view
      class="erpitem clearitem"
      style="background: pink"
      @click="clearClick()"
    >
      <view class="erpitem_img">
        <image src="../../static/image/kucun.png" mode=""></image>
      </view>
      <text>商品清洗</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      // 收银台权限
      i: "3",
      // 分类管理权限
      category: "2",
      // 归还管理权限
      return: "1",
      // 商品清洗权限
      clear: "2",
      // 财务报表权限
      finance: "1",
      // 会员卡管理权限
      vipcard: "4",
      // 订单管理权限
      order: "5",
      // 商品管理权限
      goods: "6",
    };
  },

  onLoad() {
    var loginRes = this.checkLogin();
    if (!loginRes) {
      return false;
    }
  },
  created() {},
  methods: {
    // 会员卡管理
    vipCardClick() {
      uni.request({
        url: "http://gxyckf.1qit.com/api/admin.user_card_hand/rule",
        data: {
          i: this.vipcard,
        },
        method: "POST",
        header: {
          token: uni.getStorageSync("token"),
        },
        success: (res) => {
          console.log(res.data);
          if (res.data.code === 1504) {
            uni.showToast({
              title: "无权限访问",
              icon: "error",
              duration: 2000,
            });
            uni.navigateTo({
              url: "pages/erp/erp",
            });
          } else {
            uni.navigateTo({
              url: "../vipcard/vipcard",
            });
          }
        },
      });
    },
    // 商品清洗
    clearClick() {
      console.log("商品清洗");
      uni.request({
        url: "http://gxyckf.1qit.com/api/admin.clear/rule",
        data: {
          i: this.clear,
        },
        method: "POST",

        header: {
          token: uni.getStorageSync("token"),
        },
        success: (res) => {
          console.log(res.data);
          if (res.data.code === 1504) {
            uni.showToast({
              title: "无权限访问",
              icon: "error",
              duration: 2000,
            });
            uni.navigateTo({
              url: "pages/erp/erp",
            });
          } else {
            uni.navigateTo({
              url: "../clear/clear",
            });
          }
        },
      });
    },
    adminClick() {
      uni.request({
        url: "http://gxyckf.1qit.com/api/admin.cashier/rule",
        data: {
          i: this.i,
        },
        header: {},
        success: (res) => {
          console.log(res.data);
          if (res.data.code === 1504) {
            uni.showToast({
              title: "无权限访问",
              icon: "error",
              duration: 2000,
            });
            uni.navigateTo({
              url: "pages/erp/erp",
            });
          } else {
            uni.navigateTo({
              url: "../adminstration/adminstration",
            });
          }
        },
      });
    },
    // 分类管理
    classification() {
      uni.request({
        url: "http://gxyckf.1qit.com/api/admin.cashier/rule",
        data: {
          i: this.category,
        },
        method: "POST",
        header: {
          token: uni.getStorageSync("token"),
        },
        success: (res) => {
          if (res.data.code === 1504) {
            uni.showToast({
              title: "无权限访问",
              icon: "error",
              duration: 2000,
            });
            uni.navigateTo({
              url: "pages/erp/erp",
            });
          } else {
            uni.navigateTo({
              url: "../classification/classification",
            });
          }
        },
      });
    },
    // 订单管理
    orderlistClick() {
      uni.request({
        url: "http://gxyckf.1qit.com/api/admin.order/rule",
        data: {
          i: this.order,
        },
        method: "POST",
        header: {
          token: uni.getStorageSync("token"),
        },
        success: (res) => {
          if (res.data.code === 1504) {
            uni.showToast({
              title: "无权限访问",
              icon: "error",
              duration: 2000,
            });
            uni.navigateTo({
              url: "pages/erp/erp",
            });
          } else {
            uni.navigateTo({
              url: "../orderlist/orderlist",
            });
          }
        },
      });
    },
    stockClick() {
      uni.request({
        url: "http://gxyckf.1qit.com/api/admin.cashier/rule",
        data: {
          i: this.i,
        },
        header: {
          token: uni.getStorageSync("token"),
        },
        success: (res) => {
          if (res.data.code === 1504) {
            uni.showToast({
              title: "无权限访问",
              icon: "error",
              duration: 2000,
            });
            uni.navigateTo({
              url: "pages/erp/erp",
            });
          } else {
            uni.navigateTo({
              url: "../stock/stock",
            });
          }
        },
      });
    },
    // 财务报表
    financeClick() {
      uni.request({
        url: "http://gxyckf.1qit.com/api/admin.statistics/rule",
        data: {
          i: this.finance,
        },
        method: "POST",
        header: {
          token: uni.getStorageSync("token"),
        },
        success: (res) => {
          console.log(res.data);
          if (res.data.code === 1504) {
            uni.showToast({
              title: "无权限访问",
              icon: "error",
              duration: 2000,
            });
            uni.navigateTo({
              url: "pages/erp/erp",
            });
          } else {
            uni.navigateTo({
              url: "../finance/finance",
            });
          }
        },
      });
    },
    goodsadminClick() {
      uni.request({
        url: "http://gxyckf.1qit.com/api/admin.goods/rule",
        data: {
          i: this.goods,
        },
        method: "POST",
        header: {
          token: uni.getStorageSync("token"),
        },
        success: (res) => {
          console.log(res.data);
          if (res.data.code === 1504) {
            uni.showToast({
              title: "无权限访问",
              icon: "error",
              duration: 2000,
            });
            uni.navigateTo({
              url: "pages/erp/erp",
            });
          } else {
            uni.navigateTo({
              url: "../goodsadmin/goodsadmin",
            });
          }
        },
      });
    },
    // 归还管理
    returnClick() {
      uni.request({
        url: "http://gxyckf.1qit.com/api/admin.cashier/rule",
        data: {
          i: this.return,
        },
        method: "POST",

        header: {
          token: uni.getStorageSync("token"),
        },
        success: (res) => {
          console.log(res.data);
          if (res.data.code === 1504) {
            uni.showToast({
              title: "无权限访问",
              icon: "error",
              duration: 2000,
            });
            uni.navigateTo({
              url: "pages/erp/erp",
            });
          } else {
            uni.navigateTo({
              url: "../return/return",
            });
          }
        },
      });
    },
    cashierClick() {
      // 调接口;
      uni.request({
        url: "http://gxyckf.1qit.com/api/admin.cashier/rule",
        data: {
          i: this.i,
        },
        method: "POST",

        header: {
          token: uni.getStorageSync("token"),
        },
        success: (res) => {
          if (res.data.code === 1504) {
            uni.showToast({
              title: "无权限访问",
              icon: "error",
              duration: 2000,
            });
            uni.navigateTo({
              url: "pages/erp/erp",
            });
          } else if (res.data.code === 401) {
            console.log("未登录");
          } else {
            uni.navigateTo({
              url: "../cashier/cashier",
            });
          }
        },
      });
    },
  },
};
</script>

<style>
page {
  /* background: #62beff; */
}
.erplist {
  display: flex;
  /* align-items: center; */
  /* justify-content: space-between; */
  flex-wrap: wrap;
  /* margin: 50% 0; */
  /* background: #62beff; */
}
.erplist:after {
  display: block;
  content: "";
  width: 32.7%;
  height: 0rpx;
}
.erpitem {
  width: 32.7%;
  padding: 12% 0;
  font-size: 28rpx;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1rpx solid #fff;
}
.clearitem {
  text-align: left;
}
.erpitem .erpitem_img {
  /* background: #ccc; */
  width: 100rpx;
  border-radius: 50rpx;
  margin-bottom: 10%;
  height: 100rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}
.erpitem .erpitem_img image {
  width: 50rpx;
  height: 50rpx;
}
.erpitem text {
}
</style>
